package SGUI

import (
	. "SGEngine2"
	"dom4g"
	"fmt"
)

func GenTreeByXml(elem *dom4g.Element, node *Node, tw *TopWidget, p IWidget) IWidget {
	t := &TreeView{}
	return t
}

func treeChildParse(widget IWidget, elem *dom4g.Element) {
	node := elem.AllNodes()[0]
	widget.(*TreeView).ItemTemplate = node
}

const (
	TreeItem_Opened = 0
	TreeItem_Closed = 1
)

type TreeItem struct {
	Text  string
	State int
	Child []*TreeItem
}

type TreeView struct {
	WidgetInfo
	TreeItems    []*TreeItem
	ItemTemplate *dom4g.Element
}

func (this *TreeView) OnEnable(node *Node) {
	bdata := this.GetAttr("BindData")
	if bdata == nil {
		fmt.Println("BindData is nil")
	}
	this.TreeItems = bdata.([]*TreeItem)
	this.GenTree()
}

func (this *TreeView) GenTree() {
	this.GenTreeItem(this.TreeItems, -1)
}

func (this *TreeView) GenTreeItem(Items []*TreeItem, spaceNum int) {
	spaceNum += 1
	for i := 0; i < len(Items); i++ {
		this.GenTreeItemWidget(Items[i], spaceNum)
		this.GenTreeItem(Items[i].Child, spaceNum)
	}
}

func (this *TreeView) GenTreeItemWidget(item *TreeItem, spaceNum int) {

}

func (this *TreeView) GetWidgetInfo() *WidgetInfo {
	return &this.WidgetInfo
}
